package cn.kgc.spring.shop.controller;


import cn.kgc.spring.shop.entity.ServiceAppoint;
import cn.kgc.spring.shop.service.ServiceAppointService;
import cn.kgc.spring.shop.service.ServiceEvaluateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyc
 * @since 2022-10-20
 */
@RestController
@RequestMapping("/shop/service-appoint")
public class ServiceAppointController {

    @Resource
    ServiceAppointService appointService;
    @Autowired
    ServiceEvaluateService serviceEvaluateService;

    @GetMapping("input")
    public Map<String,Object> input(@RequestParam(required = true) String number){
        Map<String,Object> map=new HashMap<>();
        QueryWrapper<ServiceAppoint> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("number",number);
        ServiceAppoint one = appointService.getOne(queryWrapper);
        map.put("code","0000");
        if (one==null){
            map.put("msg","未查到信息");
        }else {
            map.put("service",one);
        }
        return map;
    }
    @PostMapping("verification")
    public Map<String,Object> verification(Integer status,String number){
        Map<String,Object> map=new HashMap<>();
        QueryWrapper<ServiceAppoint> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("number",number);
        ServiceAppoint one = appointService.getOne(queryWrapper);
        one.setVerificationStatus(status);
        boolean update = appointService.updateById(one);
        map.put("code","0000");
        map.put("msg",update);
        return map;
    }
    @PostMapping("appraise")
    public  Map<String,Object> appraise(String number,Integer score,String evaluate,String suggest ){
        Map<String,Object> map=new HashMap<>();
        boolean insert = serviceEvaluateService.insert1(number, score, evaluate, suggest);
        map.put("msg","哦了！");
        map.put("code",0000);
        return  map;
    }
}

